
<script setup>
import { reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useToken } from '@/stores'
import {login} from "@/api/user.js"
const router = useRouter()
const loginForm=reactive({
  username:"demo",
  password:"zh@hm#23"
})
// 
const onFinish = async (values) => {
  const { setToken } = useToken()
  const res = await login(values)
  console.log(res.data.token)
  setToken(res.data.token) // 设置token
  router.push('/')
}
</script>
<template>
  <div class="login-container">
    <div class="logo">
      <div class="icon"></div>
      <!-- <img src="@/assets/common/login.svg" width="300" alt="" /> -->
      <!-- <p>开箱即用的中后台管理系统</p> -->
    </div>
    <div class="form">
      <h3>智慧园区---登录</h3>
      <a-card class="login-card">
         <!--  -->
         <a-form :model="loginForm" @finish="onFinish">
          <a-form-item
          label="账号"
            name="username"
            :rules="[
              { required: true, message: '请输入账号!', trigger: 'blur' }]"
          >
            <a-input v-model:value="loginForm.username" placeholder="请输入账号"></a-input>
          </a-form-item>
          <a-form-item
          label="密码"
            name="password"
            :rules="[{ required: true, message: '密码不能为空', trigger: 'blur' }]"
          >
            <a-input-password
              v-model:value="loginForm.password"
              placeholder="请输入密码"
            ></a-input-password>
          </a-form-item>
          <a-form-item
          >
            <a-checkbox >记住我</a-checkbox>
          </a-form-item>
          <a-form-item>
            <a-button type="primary" block html-type="submit">登录</a-button>
          </a-form-item>
        </a-form>
      </a-card>
    </div>
  </div>
</template>

<style lang="less">
.login-container {
  display: flex;
  align-items: stretch;
  height: 100vh;
  .logo {
    flex: 3;
    background: rgba(38, 72, 176) url(https://fe-hmzs.itheima.net/assets/login-bg-e4ea539c.svg) no-repeat center / cover;
    border-top-right-radius: 60px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 0 100px;
    .icon {
      // background: url(../../assets/common/logo.png) no-repeat 70px center / contain;
      width: 300px;
      height: 50px;
      margin-bottom: 50px;
    }
    p {
      color: #fff;
      font-size: 18px;
      margin-top: 20px;
      width: 300px;
      text-align: center;
    }
  }
  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 50px;
    .ant-card {
      width: 320px;
      border: none;
      padding: 0;
    }
    h3 {
      padding-left: 30px;
      font-size: 24px;
    }
  }
}
</style>
